package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: 刘安杰
 * @Date: 2024/8/14
 * @Time: 18:34
 * @Description:
 */
//全局异常处理器
@RestControllerAdvice //@ControllerAdvice + @ResponseBody
public class GlobalExceptionHandler {

    //处理异常的方法
@ExceptionHandler(value = Exception.class)
    public Result doResolveException(Exception e){
    e.printStackTrace();
    return Result.fail();
}

//处理自定义异常的方法
    @ExceptionHandler(value = LeaseException.class)
    public Result doResolveLeaseException(LeaseException e){
    e.printStackTrace();
    return Result.fail(e.getCode(),e.getMessage());
    }
}
